package org.mat.ipaas.ucenter.service.api.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.constant.CacheConstant;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysDictDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.SysDictTreeDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.TreeSelectModelDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.DictModelDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.DictQueryDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.lowapp.SysDictVoDTO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @Author zhangweijian
 * @since 2018-12-28
 */
@FeignClient(name = "mat-ipaas-ucenter-service", contextId = "sys-dict-rest-api")
public interface SysDictRestAPI {

    @RequestMapping(value = "/sys/dict/list", method = RequestMethod.GET)
    MatApiResponse<Page<SysDictDTO>> queryPageList(@SpringQueryMap SysDictDTO sysDictDTO,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    /**
     * @param sysDictDTO
     * @param pageNo
     * @param pageSize
     * @return
     * @功能：获取树形字典数据
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/sys/dict/treeList", method = RequestMethod.GET)
    MatApiResponse<List<SysDictTreeDTO>> treeList(@SpringQueryMap SysDictDTO sysDictDTO,
                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    /**
     * 获取全部字典数据
     *
     * @return
     */
    @RequestMapping(value = "/sys/dict/queryAllDictItems", method = RequestMethod.GET)
    MatApiResponse<?> queryAllDictItems(@RequestParam HttpServletRequest request);

    /**
     * 获取字典数据
     *
     * @param dictCode
     * @return
     */
    @RequestMapping(value = "/sys/dict/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
    MatApiResponse<String> getDictText(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key);


    /**
     * 获取字典数据 【接口签名验证】
     *
     * @param dictCode 字典code
     * @param dictCode 表名,文本字段,code字段  | 举例：sys_user,realname,id
     * @return
     */
    @RequestMapping(value = "/sys/dict/getDictItems/{dictCode}", method = RequestMethod.GET)
    MatApiResponse<List<DictModelDTO>> getDictItems(@PathVariable("dictCode") String dictCode, @RequestParam(value = "sign", required = false) String sign, @RequestParam HttpServletRequest request);

    /**
     * 【接口签名验证】
     * 【JSearchSelectTag下拉搜索组件专用接口】
     * 大数据量的字典表 走异步加载  即前端输入内容过滤数据
     *
     * @param dictCode 字典code格式：table,text,code
     * @return
     */
    @RequestMapping(value = "/sys/dict/loadDict/{dictCode}", method = RequestMethod.GET)
    MatApiResponse<List<DictModelDTO>> loadDict(@PathVariable("dictCode") String dictCode,
                                                @RequestParam(name = "keyword", required = false) String keyword,
                                                @RequestParam(value = "sign", required = false) String sign,
                                                @RequestParam(value = "pageSize", required = false) Integer pageSize);

    /**
     * 【接口签名验证】
     * 【给表单设计器的表字典使用】下拉搜索模式，有值时动态拼接数据
     *
     * @param dictCode
     * @param keyword  当前控件的值，可以逗号分割
     * @param sign
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/sys/dict/loadDictOrderByValue/{dictCode}", method = RequestMethod.GET)
    MatApiResponse<List<DictModelDTO>> loadDictOrderByValue(
            @PathVariable("dictCode") String dictCode,
            @RequestParam(name = "keyword") String keyword,
            @RequestParam(value = "sign", required = false) String sign,
            @RequestParam(value = "pageSize", required = false) Integer pageSize);

    /**
     * 【接口签名验证】
     * 根据字典code加载字典text 返回
     *
     * @param dictCode    顺序：tableName,text,code
     * @param keys        要查询的key
     * @param sign
     * @param delNotExist 是否移除不存在的项，默认为true，设为false如果某个key不存在数据库中，则直接返回key本身
     * 
     * @return
     */
    @RequestMapping(value = "/sys/dict/loadDictItem/{dictCode}", method = RequestMethod.GET)
    MatApiResponse<List<String>> loadDictItem(@PathVariable("dictCode") String dictCode, @RequestParam(name = "key") String keys, @RequestParam(value = "sign", required = false) String sign, @RequestParam(value = "delNotExist", required = false, defaultValue = "true") boolean delNotExist, @RequestParam HttpServletRequest request);

    /**
     * 【接口签名验证】
     * 根据表名——显示字段-存储字段 pid 加载树形数据
     *
     * @param hasChildField   是否叶子节点字段
     * @param converIsLeafVal 是否需要系统转换 是否叶子节点的值 (0标识不转换、1标准系统自动转换)
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/sys/dict/loadTreeData", method = RequestMethod.GET)
    MatApiResponse<List<TreeSelectModelDTO>> loadTreeData(@RequestParam(name = "pid", required = false) String pid, @RequestParam(name = "pidField") String pidField,
                                                          @RequestParam(name = "tableName") String tbname,
                                                          @RequestParam(name = "text") String text,
                                                          @RequestParam(name = "code") String code,
                                                          @RequestParam(name = "hasChildField") String hasChildField,
                                                          @RequestParam(name = "converIsLeafVal", defaultValue = "1") int converIsLeafVal,
                                                          @RequestParam(name = "condition") String condition,
                                                          @RequestParam(value = "sign", required = false) String sign, @RequestParam HttpServletRequest request);

    /**
     * 【APP接口】根据字典配置查询表字典数据（目前暂未找到调用的地方）
     *
     * @param dictQueryDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Deprecated
    @GetMapping("/sys/dict/queryTableData")
    MatApiResponse<List<DictModelDTO>> queryTableData(DictQueryDTO dictQueryDTO,
                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(value = "sign", required = false) String sign, @RequestParam HttpServletRequest request);

    /**
     * @param sysDictDTO
     * @return
     * @功能：新增
     */
    //@RequiresPermissions("system:dict:add")
    @RequestMapping(value = "/sys/dict/add", method = RequestMethod.POST)
    MatApiResponse<SysDictDTO> add(@RequestBody SysDictDTO sysDictDTO);

    /**
     * @param sysDictDTO
     * @return
     * @功能：编辑
     */
    //@RequiresPermissions("system:dict:edit")
    @RequestMapping(value = "/sys/dict/edit", method = {RequestMethod.POST})
    MatApiResponse<SysDictDTO> edit(@RequestBody SysDictDTO sysDictDTO);

    /**
     * @param id
     * @return
     * @功能：删除
     */
    //@RequiresPermissions("system:dict:delete")
    @RequestMapping(value = "/sys/dict/delete", method = RequestMethod.DELETE)
    @CacheEvict(value = {CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries = true)
    MatApiResponse<SysDictDTO> delete(@RequestParam(name = "id", required = true) String id);

    /**
     * @param ids
     * @return
     * @功能：批量删除
     */
    //@RequiresPermissions("system:dict:deleteBatch")
    @RequestMapping(value = "/sys/dict/deleteBatch", method = RequestMethod.DELETE)
    @CacheEvict(value = {CacheConstant.SYS_DICT_CACHE, CacheConstant.SYS_ENABLE_DICT_CACHE}, allEntries = true)
    MatApiResponse<SysDictDTO> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    /**
     * @return
     * @功能：刷新缓存
     */
    @RequestMapping(value = "/sys/dict/refleshCache")
    MatApiResponse<?> refleshCache();

    /**
     * 导出excel
     *
     * 
     */
    @RequestMapping(value = "/sys/dict/exportXls")
    ModelAndView exportXls(SysDictDTO sysDictDTO, @RequestParam HttpServletRequest request);

    /**
     * 通过excel导入数据
     *
     * 
     * @param
     * @return
     */
    //@RequiresPermissions("system:dict:importExcel")
    @RequestMapping(value = "/sys/dict/importExcel", method = RequestMethod.POST)
    MatApiResponse<?> importExcel( );


    /**
     * 查询被删除的列表
     *
     * @return
     */
    @RequestMapping(value = "/sys/dict/deleteList", method = RequestMethod.GET)
    MatApiResponse<List<SysDictDTO>> deleteList();

    /**
     * 物理删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/sys/dict/deletePhysic/{id}", method = RequestMethod.DELETE)
    MatApiResponse<?> deletePhysic(@PathVariable("id") String id);

    /**
     * 逻辑删除的字段，进行取回
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/sys/dict/back/{id}", method = RequestMethod.PUT)
    MatApiResponse<?> back(@PathVariable("id") String id);

    /**
     * 根据应用id获取字典列表和详情
     *
     * 
     */
    @GetMapping("/sys/dict/getDictListByLowAppId")
    MatApiResponse<List<SysDictVoDTO>> getDictListByLowAppId(@RequestParam HttpServletRequest request);

    /**
     * 添加字典
     *
     * @param sysDictVoDTO
     * 
     * @return
     */
    @PostMapping("/sys/dict/addDictByLowAppId")
    MatApiResponse<String> addDictByLowAppId(@RequestBody SysDictVoDTO sysDictVoDTO, @RequestParam HttpServletRequest request);

    @PutMapping("/sys/dict/editDictByLowAppId")
    MatApiResponse<String> editDictByLowAppId(@RequestBody SysDictVoDTO sysDictVoDTO, @RequestParam HttpServletRequest request);
}
